%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% File:               representatives_game_line.m
%
% Author:             Miguel R. Rueda and Sergio Ascencio
%
% Description:        Computes structural parameters with two step ML
% (extra variable)
%
% Language:           MATLAB R2013b (8.2.0.701) 64 Bit
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [betas,hessian,phats,LL,auxLL,Llong]=representatives_game_line(Y,X,state,CLv_PAN,CLv_PRI,b,beta_p)

%First stage results
if state==1
    [phats,~]=first_stage(Y,X,CLv_PAN,CLv_PRI);
else
    [phats,~]=first_stage(Y,X);
end

%Second stage results
if nargin<7
    [beta,LL,hessian,auxLL,Llong]=Params2_line(Y,X,phats,b);
    betas=reshape(beta,[length(beta)/4,4]);
else
    [beta,LL,hessian,auxLL,Llong]=Params2_line(Y,X,phats,b,beta_p);
    betas=reshape(beta,[length(beta)/4,4]);
end

end